<?php require_once('Connections/conex.php'); ?>
<?php


if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  $insertSQL = sprintf("INSERT INTO postulantes (nombre, apellido, telefono, domicilio, nacimiento) VALUES (%s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['nombre'], "text"),
                       GetSQLValueString($_POST['apellido'], "text"),
                       GetSQLValueString($_POST['telefono'], "text"),
                       GetSQLValueString($_POST['domicilio'], "text"),
                       GetSQLValueString($_POST['ano'].$_POST['mes'].$_POST['dia'], "date"));

  mysql_select_db($database_conex, $conex);
  $Result1 = mysql_query($insertSQL, $conex) or die(mysql_error());
  
  
  //---aca agarro el id que insertó la base de datos automáticamente, y lo guardo en una variable de session
  $_SESSION['id'] = mysql_insert_id();

  $insertGoTo = "postulantes_cargar2.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}
?>

<?php
$PAGE = 'postulantes_cargar';
$TIPO = 'frontend';
$TITLE = 'Cargar Currículum';
?> 

<!-- empieza la página-->

   
   <?php include('includes/head.php') ?>
   
    <body id="<?php echo $PAGE; ?>" class="<?php echo $PAGE; ?>">
     
     <?php include('includes/cabecera.php') ?>
       
     <?php include('includes/intro.php') ?>
        
     <?php if ($PAGE == 'home') { ?>
     <?php include('includes/cols.php') ?>
     <?php } ?>
        
     <div id="contenido">
     
     	<div id="main">

                <h1>Cargar Currículum</h1>
                <h2>Datos Personales</h2>
                <form method="post" name="form1" action="<?php echo $editFormAction; ?>">
                  <table>
                    <tr valign="baseline">
                      <td nowrap align="right">Nombre:</td>
                      <td><input type="text" name="nombre" value="" size="32"></td>
                    </tr>
                    <tr valign="baseline">
                      <td nowrap align="right">Apellido:</td>
                      <td><input type="text" name="apellido" value="" size="32"></td>
                    </tr>
                    <tr valign="baseline">
                      <td nowrap align="right">Teléfono:</td>
                      <td><input type="text" name="telefono" value="" size="32"></td>
                    </tr>
                    <tr valign="baseline">
                      <td nowrap align="right">Domicilio:</td>
                      <td><input type="text" name="domicilio" value="" size="32"></td>
                    </tr>
                     <tr valign="baseline">
                      <td nowrap align="right">&nbsp;</td>
                      <td>&nbsp;</td>
                    </tr>
                    <tr valign="baseline">
                      <td nowrap align="right">Fecha de Nacimiento:</td>
                      <td></td>
                    </tr>
                   <tr valign="baseline">
                   	<td nowrap align="right">Día</td>
                    <td>
                    <select name="dia">
                    <?php for($dia=01; $dia<=31; $dia++) { //se generan los dias ?>
                      <option value="<?php echo(($dia < 10)?"0":"").$dia ?>"><?php echo(($dia < 10)?"0":"").$dia ?></option>
                    <?php } ?>
                    </select></td>
                   </tr>
                   <tr valign="baseline">
                   	<td nowrap align="right">Mes</td>
                    <td><select name="mes">
                    <?php for($mes=1; $mes<=12; $mes++) { //se generan los 12 meses?>
                      <option value="<?php echo(($mes < 10)?"0":"").$mes; ?>"><?php echo(($mes < 10)?"0":"").$mes; ?></option>
                    <?php } ?>
                    </select></td>
                   </tr>
                   <tr valign="baseline">
                   	<td nowrap align="right">Año</td>
                    <td><select name="ano">
                    <?php for($ano=1930; $ano<=1993; $ano++) { //se generan los años ?>
                      <option value="<?php echo $ano; ?>"><?php echo $ano; ?></option>
                    <?php } ?>
                    </select></td>
                   </tr>
                    
                    <tr valign="baseline">
                      <td nowrap align="right">&nbsp;</td>
                      <td><input type="submit" value="Aceptar y Continuar"></td>
                    </tr>
                  </table>
                  <input type="hidden" name="id" value="">
                  <input type="hidden" name="MM_insert" value="form1">
                </form>
                </div>
        
        <div id="columna">
   			<?php include('includes/columna.php') ?>
        </div>
         
            
     </div>
        
     <hr class="noscreen" />

        
     <?php include('includes/pie.php') ?>

<!-- termina la página-->